<script src="http://g.alicdn.com/sj/lib/jquery/dist/jquery.min.js"></script>
<script src="//cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdn.bootcss.com/metisMenu/1.1.3/metisMenu.min.js"></script>
<script src="https://cdn.bootcss.com/jquery.pin/1.0.1/jquery.pin.min.js"></script>
<script src="__JS__/sb-admin-2.js"></script>
<!--代码高亮-->
<script src="//cdn.bootcss.com/highlight.js/8.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>

<SCRIPT type="text/javascript" >
    $("#pin").pin({
        containerSelector: "#page-wrapper",
        minWidth: 940
    });
    // 文章内容
    target = $("#contents");
    //    目录
    var catalogue = $("#pin");
    $(document).ready(function() {
        GenerateContents2();
    });

    function GenerateContents2() {
        var num = 0;
        var target = $("#contents");
        var content = "<div class='panel-heading'>目录</div>";
        content += "<ul>";
        $("h2").each(function(){
            content += "<li>"+GenerateA(num,$(this).text());
            $(this).before(GenerateLabel(num));
            num++;

            var second = $(this).nextUntil("h2","h3");
            if (second) {
                content += "<ul>";
                second.each(function(){
                        content += "<li>"+GenerateA
                            (num,$(this).text())+"</li>";
                        $(this).before(GenerateLabel(num));
                        num++;
                    }
                );
                content += "</ul>";
            };
            content += "</li>";
        });
        content += "</ul>";
        catalogue.append(content);
    }

    //这两个函数本来想的是以后改着方便
    function GenerateLabel(num){
        var a = "<a name = 'label" + num + "'></a>";
        return a;
    }

    function GenerateA(num ,text){
        var ss = "<a href='javascript:;' data-label='" + "label"
            + num +"'>" + text
            + "</a>";
        return ss;
    }

    // 点击跳转
    $(document).ready(function() {
        $('.pin-wrapper a').click(function(){
            var label = $(this).attr('data-label');
            var scrollT = $('[name='+label+']').offset().top-60;
            $('body').scrollTop(scrollT);
        });
    });
</SCRIPT>

<!--引入js-->
{if isset($script)}
{include file="script/{$Request.controller|strtolower}/{$Request.action|strtolower}" /}
{/if}

</body>
</html>